/**
 * New node file
 */

if(enableCache=='memCache'){
		var memcache = require('memcache');
		var port = 11211;
		host=global.MemCacheHostIp;
		global.cacheClient = new memcache.Client(port, host);

		cacheClient.on('connect', function(){
			logger.info('Connected to MemCached Server -'+cacheClient.host+':'+cacheClient.port+'...!');
		});

		cacheClient.on('close', function(){
			logger.info('Connection to memCached is closed...!');
		});

		cacheClient.on('timeout', function(){
			logger.info('Time out to connect to MemCached Server....!');
		});

		cacheClient.on('error', function(err){
			logger.info('Failed to connect the memCached Server...!' + err.message);
		});

		// connect to the memcache server after subscribing to some or all of these events
		cacheClient.connect();
}else{
	//采用redis来缓冲
	var redis = require("redis");
	global.cacheClient = redis.createClient(RedisPort, global.RedisHostIp);

	cacheClient.auth(redisPassword, function () {

	});

	cacheClient.on("error", function(err){
		logger.error('Failed to connect the Redis Server - ' + err);
	});

	cacheClient.on("connect", function(){
		logger.info('Successfully to connect the Redis Server...!');
	});
}

